package org.korifey.ffalg;

import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.IntBuffer;
import java.nio.MappedByteBuffer;
import java.nio.channels.ByteChannel;
import java.nio.channels.FileChannel;
import java.nio.channels.FileChannel.MapMode;
import java.nio.file.FileSystem;
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardOpenOption;
import java.security.SecureRandom;
import java.util.Random;
import java.util.UUID;

import org.junit.Test;

public class IOUtilTest {
	
	@Test
	public void testSort() throws IOException {
		Path tmpFile = Files.createTempFile("sort_input", null);
		System.out.println(tmpFile.toAbsolutePath().toString());
		
		Random random = new Random();		
		
		//ByteChannel ch = Files.newByteChannel(tmpFile, StandardOpenOption.APPEND);
		long sum = 0;
		long n = 1 << 24;
		
		IntBuffer buf = FileChannel.open(tmpFile, StandardOpenOption.CREATE, StandardOpenOption.WRITE, StandardOpenOption.READ).map(MapMode.PRIVATE, 0, n).asIntBuffer();
		
		for (long i=0 ; i< n; i++) {
			int x = random.nextInt();
			sum += x;
			buf.put(x);
		}

		
	}
}
